package com.csu.servlet;

import com.csu.service.BorrowInfoService;
import com.csu.service.impl.BorrowInfoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "DeleteBorrowInfoServlet", urlPatterns = "/DeleteBorrowInfoServlet")
public class DeleteBorrowInfoServlet extends HttpServlet {
    private BorrowInfoService borrowInfoService = new BorrowInfoServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int borrowId = Integer.parseInt(req.getParameter("borrowId"));
        HttpSession session = req.getSession();
        if(borrowInfoService.removeInfo(borrowId)){
            session.setAttribute("msg", "删除成功！");
        }else{
            session.setAttribute("msg", "删除失败！");
        }
        resp.sendRedirect(req.getContextPath() + "/GetBorrowInfoServlet");
    }
}
